//点击单个就诊详情
var yinyongjzjlid = null;
function showJiuZhenxq(jiuzhenjlid){
	getTuxiangzl(null, jiuzhenjlid, ".jiuzhenjl-txzl", 2);
	yinyongjzjlid = jiuzhenjlid;
	$.ajax({
	    type: "get",
	    //获取json文件路径
	    url: path + "/changguimz/getById",
	    //传送数据
	    data: {id: jiuzhenjlid},
	    //请求成功完成后要执行的方法
	    success: function(data){
	    	//显示详情信息
	    	if(data!="") {
	    		/****        患者基本信息部分       ****/
	    		var huanzhexx = data.huanzhexx;
	    		$('#hz-xingming').html(huanzhexx.xingming);
	    		if(huanzhexx.xingbie==1) {
	    			$('#hz-xingbie').html('男');
	    		}else if(huanzhexx.xingbie==2){
	    			$('#hz-xingbie').html('女');
	    		}
	    		
	    		$('#hz-nianling').html(huanzhexx.nianling);
	    		if(huanzhexx.nianling != null){
	    			if(huanzhexx.nianlingdw=='岁') {
		    			$("#f-le-nianlingdw").html('岁');
		    		}else {
		    			$("#f-le-nianlingdw").html('月');
					}
	    		}else {
	    			$("#hz-hinianlingdw").hide();
	    		}
	    		$('#hz-shoujihm').html(huanzhexx.shoujihm);
	    		$('#hz-jiuzhensj').html(formatDate(data.zsJiuzhenjl.jiuzhensj,false));
	    		if(huanzhexx.guominshi!=''&&huanzhexx.guominshi!=null&&huanzhexx.guominshi!="null"){
			    		$('#hz-guominshi').html(huanzhexx.guominshi);
		    			$('#hz-guominshi').css('color','#333')
		    		}else{
		    			$('#hz-guominshi').text('（未登记过敏史）');
		    			$('#hz-guominshi').css('color','#777')
		    		}
	    		$('#div-guominshi').html(huanzhexx.guominshi);
	    		
	    		/****        病例信息部分部分       ****/
	    		console.log(data.zsJiuzhenjl.zhushu)
	    		if(data.zsJiuzhenjl.zhushu!=''&&data.zsJiuzhenjl.zhushu!=null) {
	    			$('#zhushu').html(data.zsJiuzhenjl.zhushu);
	    			$('#zhushu').css('color','#333');
	    		}else{
	    			$('#zhushu').html('（未填写主诉）');
	    			$('#zhushu').css('color','#777');
	    		}
	    		if(data.zsJiuzhenjl.xianbingshi!=''&&data.zsJiuzhenjl.xianbingshi!=null){
		    		$('#xianbings').html(data.zsJiuzhenjl.xianbingshi);
	    			$('#xianbings').css('color','#333');
	    		}else{
	    			$('#xianbings').html('（未填写现病史）');
	    			$('#xianbings').css('color','#777');
	    		}
	    		if(data.zsJiuzhenjl.jiwangshi!=''&&data.zsJiuzhenjl.jiwangshi!=null){
		    		$('#jiwangs').html(data.zsJiuzhenjl.jiwangshi);
	    			$('#jiwangs').css('color','#333');
	    		}else{
	    			$('#jiwangs').html('（未填写既往史）');
	    			$('#jiwangs').css('color','#777');
	    		}
	    		
	    		if(data.zsJiuzhenjl.tiwen==null||data.zsJiuzhenjl.tiwen=="") {
		    			$('#tiwen').css('display','none');
		    			var twfalg=false;
		    		}else{
		    			var twfalg=true;
		    			$('#tiwen').css('display','inline-block');
		    			$('#tiwen').html('体温 '+data.zsJiuzhenjl.tiwen+'°C');
		    		}
		    		if(data.zsJiuzhenjl.tizhong==null||data.zsJiuzhenjl.tizhong=="") {
		    			$('#tizhong').css('display','none');
		    			var tzflag=false;
		    		}else{
		    			$('#tizhong').css('display','inline-block');
		    			$('#tizhong').html('体重 '+data.zsJiuzhenjl.tizhong+'kg');
		    			var tzflag=true;
		    		}
		    		if(data.zsJiuzhenjl.shousuoya==null||data.zsJiuzhenjl.shousuoya=="") {
		    			$('#shousuoy').css('display','none');
		    			var ssflag=false;
		    		}else{
		    			$('#shousuoy').css('display','inline-block');
		    			$('#shousuoy').html('收缩压 '+data.zsJiuzhenjl.shousuoya+'mmHg');
		    			var ssflag=true;
		    		}
		    		if(data.zsJiuzhenjl.shuzhangya==null||data.zsJiuzhenjl.shuzhangya=="") {
		    			$('#shuzhangy').css('display','none');
		    			var szflag=false;
		    		}else{
		    			$('#shuzhangy').css('display','inline-block');
		    			$('#shuzhangy').html('舒张压 '+data.zsJiuzhenjl.shuzhangya+'mmHg');
		    			var szflag=true;
		    		}
		    		if(data.zsJiuzhenjl.xinlv==null||data.zsJiuzhenjl.xinlv=="") {
		    			$('#xinlv').css('display','none');
		    			var xlflag=false;
		    		}else{
		    			$('#xinlv').css('display','inline-block');
		    			$('#xinlv').html('心率 '+data.zsJiuzhenjl.xinlv+'次/分');
		    			var xlflag=true;
		    		}
		    		if(data.zsJiuzhenjl.qitatz==null||data.zsJiuzhenjl.qitatz=="") {
		    			$('#qita').css('display','none');
		    			var qitaflag=false;
		    		}else{
		    			$('#qita').css('display','inline-block');
		    			$('#qita').val('其他 '+data.zsJiuzhenjl.qitatz);
		    			var qitaflag=true;
		    		}
		    		var xinlvzb = "";
		    		if(data.zsJiuzhenjl.xinlvzb==1) {
		    			xinlvzb = "心律正常";
		    		}else if(data.zsJiuzhenjl.xinlvzb==0) {
		    			xinlvzb = "心律不齐";
		    		}
		    		if(data.zsJiuzhenjl.xinlvzb!=0&&data.zsJiuzhenjl.xinlvzb!=1) {
		    			$('#xinlvzb').css('display','none');
		    			var xlzbflag=false;
		    		}else{
		    			$('#xinlvzb').css('display','inline-block');
		    			var xlzbflag=true;
		    			$('#xinlvzb').html('心律指标 '+xinlvzb);
		    		}
		    		if(!xlzbflag&&!qitaflag&&!xlflag&&!szflag&&!ssflag&&!tzflag&&!twfalg){
		    			$('#tigejc').html('（未做任何检查）');
		    			$('#tigejc').css('color','#777');
		    		}
		    		
		    		if(data.zsJiuzhenjl.yizhu!=''&&data.zsJiuzhenjl.yizhu!=null){
			    		$('#yizhu').html(''+data.zsJiuzhenjl.yizhu);
		    			$('#yizhu').css('color','#333');
		    		}else{
		    			$('#yizhu').html('（未填写医嘱）');
		    			$('#yizhu').css('color','#777');
		    		}
		    		/*if(data.zsJiuzhenjl.qitatz!=''&&data.zsJiuzhenjl.qitatz!=null) {
		    			$('#qitatz').text('体温 '+data.zsJiuzhenjl.tiwen+'°C'+' '+'体重 '+data.zsJiuzhenjl.tizhong+'kg'+' '+'收缩压 '+data.zsJiuzhenjl.shousuoya+'mmHg'+' '+'舒张压 '+data.zsJiuzhenjl.shuzhangya+'mmHg'+' '+'心率 '+data.zsJiuzhenjl.xinlv+'次/分'+' '+'其他 '+data.zsJiuzhenjl.qitatz+' '+'心律指标 '+xinlvzb);
		    			$('#qitatz').css('color','#333');
		    		}else{
		    			$('#qitatz').text('（未填写其它体征）');
		    			$('#qitatz').css('color','#777');
		    		}*/
		    		var yishengid = data.zsJiuzhenjl.yishengid;
	    		//诊断
	    		var zsJiuzhenzds = data.zsJiuzhenzds;
	    		var zdStr = '';
	    		$(zsJiuzhenzds).each(function(i,e){
	    			if(i==0) {
	    				zdStr += this.jibingmc;
	    			}else {
	    				zdStr +=',' + this.jibingmc ;
					}
	    			
	    		});
	    		$('#zhenduan').text(zdStr);
	    		
	    		/****        处方部分       ****/
	    		var exZsChengyaocfs = data.exZsChengyaocfs;
	    		$('#chengyaocfmxdiv').html('');
	    		if(exZsChengyaocfs!="") {
	    			var chengyaostr = '';
	    			$(exZsChengyaocfs).each(function(index, value){
	    			    chengyaostr += "<p>成药处方" + (index + 1) + "<span onclick='saveCyChengYaocf(" + JSON.stringify(value) + ",\"" + zdStr + "\"," + yishengid + ")'>存为常用处方</span></p>"
		      						+'<table width="100%" cellpadding="0" border="0" cellspacing="0">'
					                + '<thead>'
					                    + '<tr>'
					                        + '<th width="40%" class="left">药品名称</th>'
					                        + '<th width="20%">用法</th>'
					                        + '<th width="20%">用药频率</th>'
					                        + '<th width="20%">开药量</th>'
					                    	+ '</tr>'
					                + '</thead>';
	    				// 成药药品遍历
	    				var yaopins = this.exYaopins;
						$(yaopins).each(function(i, v){
							chengyaostr +=
								'<tr>'+
									'<td style="text-align: left;">'+this.yaopinmc+'</td>'+
									'<td>'+this.yongfa+'</td>'+
									'<td>'+this.yongyaopl+'</td>'+
									'<td>'+this.kaiyaoliang+this.kaiyaodw+'</td>'+
								'</tr>';
						});  
						chengyaostr += '</table>';
	    			});
	    			
		    			$('#chengyaocfmxdiv').html('');
		    			$('#chengyaocfmxdiv').html(chengyaostr);
		    		}
	    		
	    		var exZsCaoyaocfs = data.exZsCaoyaocfs;
	    		$('#caoyaocfdiv').html('');
	    		if(exZsCaoyaocfs!="") {
	    			var caoyaostr = '';
	    			$(exZsCaoyaocfs).each(function(i, v){
	    			    caoyaostr += "<p>中药处方" + (i + 1) +"<span onclick='saveCyCaoYaocf(" + JSON.stringify(v) + ",\"" + zdStr + "\"," + yishengid + ")'>存为常用处方</span></p>"
	          					  + '<table width="100%" cellpadding="0" border="0" cellspacing="0">'
					                + '<thead>'
					                   + '<tr>'
					                        + '<th width="15%">剂数</th>'
					                        + '<th width="15%">用药频率</th>'
					                        + '<th width="15%">每日剂数</th>'
					                        + '<th width="15%">用法</th>'
					                        + '<th width="40%" class="left">服用要求</th>'
					                    + '</tr>'
					                + '</thead>'
					                	+ '<tbody>'
					                	+ '<tr>'
					                        + '<td width="15%">' + this.zsCaoyaocf.tieshu + '剂</td>'
					                        + '<td width="15%">' + this.zsCaoyaocf.yongyaopl + '</td>'
					                        + '<td width="15%">' + this.zsCaoyaocf.meirijl + '</td>'
					                        + '<td width="15%">' + this.zsCaoyaocf.yongfa + '</td>'
					                        + '<td width="40%" class="left">' + this.zsCaoyaocf.fuyongyq + '</td>'
					                    + '</tr>';
	    				// 草药药品遍历
	    				var yaopins = this.exYaopins;
	    				caoyaostr += '<tr><td colspan=5 class="left yinpian-box">';
						$(yaopins).each(function(i, v){
							caoyaostr += '<span class="yinpian">' + this.yaopinmc + '(' + this.danjiliang + this.danwei + ')' + this.beizhu +'</span>';
						});
						caoyaostr += '</td></tr></tbody></table>';
	    			});
	    			
	    				$('#caoyaocfdiv').html('');
		    			$('#caoyaocfdiv').html(caoyaostr);
		    		}
			}
	    }
	});
	$('.sd-right').css('display','none');
	$("#dakai").removeClass("fa-minus").addClass("fa-plus");
}

//加载患者历史就诊-分页
function showHuanzhelsjz() {
	var totalNumber = 0;
	$.ajax({
	    type: "get",
	    //获取json文件路径
	    url: path + "/huanzhe/getHuanzhejzjlCount",
	    //传送数据
	    data: {id: huanzheid},
	    async: false,
	    //请求成功完成后要执行的方法
	    success: function(data){
	    	totalNumber = data;
	    }
	});

	function createHzlsjz(name) {
	var container = $('#pagination-'+name);
	$("#tbjiuzjl").html('');
	container.pagination({
		dataSource:path+'/huanzhe/getHuanzhejzjl?id='+huanzheid,
		locator: 'entities',
		pageSize: 8,
		totalNumber: totalNumber,
		callback: function(data, pagination) {
			if(data!="") {
				$("#tbjiuzjl").html('');
				var content = '';
				jiuzhenjlid2 = data[0].id;
	    		$(data).each(function(index,element){
	    			jzjlid=data[index].id;
	    			content+="<tr id='"+data[index].id+"' class='hello' style='width:40px' onclick='showJiuZhenxq("+this.id+")'>"
	            	+ "<td class='col-sm-1'>"+(((pagination.pageNumber-1)*pagination.pageSize)+index+1)+"</td>"
	                + '<td class="col-sm-1">' +this.jiuzhenrq + '</td>' 
	                + '<td class="col-sm-1">' +this.yishengmc + '</td>'
	                + '</tr>';
	               
	    		});
	    		$("#tbjiuzjl").html(content);
	    	}
		}
	});
		return container;
	}
	createHzlsjz('fenyhzjzjl');
	if(totalNumber <= 8) {
		$('#pagination-fenyhzjzjl').css('display','none');
	}
}
$('.btn-jzjl-xqjl').click(function(){
	var icon=$(this).find("i");
	if(icon.hasClass("fa-plus")){
		$('#tbjiuzjl').find('td').removeClass('xq-color');
		$('#tbjiuzjl').find('tr[id="'+yinyongjzjlid+'"] td').addClass('xq-color');
		icon.removeClass("fa-plus").addClass("fa-minus");
		$('#hzjiuzhenjilu').css('display','block');
	}else{
		icon.removeClass("fa-minus").addClass("fa-plus");
		$('#hzjiuzhenjilu').css('display','none');
	}
});

/** 
 * @Title: saveCyChengYaocf 
 * @Description: 保存常用成药处方
 * @param chengyaocf
 * @param zhenduan
 * @param yishengid
 */
function saveCyChengYaocf(chengyaocf, zhenduan, yishengid){
    $.ajax({
        type: 'post',
        url: path + '/chufangmb/saveCyChengyaocf',
        data: {"ZsChengyaocf": JSON.stringify(chengyaocf),
                "zhenduan": zhenduan,
                "yishengid": yishengid},
        success: function(data){
            if (data == MSG_SUCCESS) {
                notifySuccess('存为常用成药处方成功');
            } else if (data == MSG_CHONGFUBZ) {
                notifyWarning('该诊断已存在同名成药处方');
            } else {
                notifyWarning('存为常用成药处方失败');
            }
        }
    });
};

/** 
 * @Title: saveCyCaoYaocf 
 * @Description: '存为常用草药处方
 * @param caoyaocf
 * @param zhenduan
 * @param yishengid
 */
function saveCyCaoYaocf(caoyaocf, zhenduan, yishengid) {
    $.ajax({
       type: 'post',
       url: path + '/chufangmb/saveCyCaoYaocf',
       data: {"ZsCaoyaocf": JSON.stringify(caoyaocf),
           "zhenduan": zhenduan,
           "yishengid": yishengid},
       success: function(data){
           if (data == MSG_SUCCESS) {
               notifySuccess('存为常用草药处方成功');
           } else if (data == MSG_CHONGFUBZ) {
               notifyWarning('该诊断已存在同名草药处方');
           } else {
               notifyWarning('存为常用草药处方失败');
           }
       }
    });
}

